package com.cn.study.first.stage.zuoye5;

import java.util.Random;
import java.util.Scanner;

public class FifthQuestion {
    public static void main(String[] args) {
        String[][] str = new String[17][17];
        for (int i = 0; i < str.length; i++) {
            for (int j = 0; j < str[0].length; j++) {
                if (i == 0) {
                    str[i][j] = String.format("%x", j - 1);
                } else if (j == 0) {
                    str[i][j] = String.format("%x", i - 1);
                } else {
                    str[i][j] = "+";
                }
            }
        }

        // 修改第一个元素为空格
        str[0][0] = " ";
        for (int i = 0; i < str.length; i++) {
            for (int j = 0; j < str[i].length; j++) {
                System.out.print(str[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static class ThirdQuestion {
        public static void main(String[] args) {

            //单注最高奖金
            int maxMoney = 1000;
            //输入蓝球的号码
            System.out.print("请输入你购买的蓝色球号码：");
            Scanner input = new Scanner(System.in);
            int blueBall = input.nextInt();
            //输入红球的数组
            int[] redBall = new int[6];
            System.out.print("请输入你购买的红色球号码(不重复)：");
            for (int i = 0; i < redBall.length; i++) {
                redBall[i] = input.nextInt();
            }
            //输出输入值
            System.out.println("----------------");
            System.out.print("你购买的红色球号码是：");
            for (int i = 0; i < redBall.length; i++) {
                System.out.print(redBall[i]+",");
            }
            System.out.println();
            System.out.println("你购买的蓝色球号码是："+blueBall);
            System.out.println("---正在产生中奖号码---");

            //生成的蓝球号码
            Random numsRandom = new Random();
            int blueBallRandom = numsRandom.nextInt(16)+1;

            //生成红球的号码
            int[] redBallRandom = new int[6];
            int index = redBallRandom.length;
            int inputRandom = 0;
            int k = 0;
            while (index>0) {

                if (exist(redBallRandom, inputRandom)) {
                    //在数组中存在,更换一个随机数
                    inputRandom = numsRandom.nextInt(33)+1;
                }else {
                    //在数组中不存在
                    redBallRandom[k] = inputRandom;
                    k++;
                    index--;
                }
            }

            //输出中奖号码
            System.out.println("蓝色球的中奖号码是："+blueBallRandom);
            System.out.print("红色球的中奖号码是：");
            for (int i = 0; i < redBallRandom.length; i++) {
                System.out.print(redBallRandom[i]+",");
            }
            System.out.println();


            //统计和蓝球相等的个数
            int blueCount = 0;
            if (blueBall == blueBallRandom) {
                blueCount = 1;
            }

            //统计和红球相等的个数
            int redCount = 0;
            for (int i = 0; i < redBallRandom.length; i++) {
                if (redBall[i] == redBallRandom[i]) {
                    redCount++;
                }
            }


            //判断是否中奖
            if (blueCount == 0 && redCount <= 3) {
                //未中奖
                System.out.println("很遗憾，您未中奖，赌博害人，请勿上头！");
                //中奖
            }else if(blueCount == 1 && redCount < 3) {
                System.out.println("恭喜你，中了六等奖，您的奖金为5元");

            }else if((blueCount == 1 && redCount == 3) || (blueCount == 0 && redCount == 4)) {
                System.out.println("恭喜你，中了五等奖，您的奖金为10元");

            }else if((blueCount == 1 && redCount == 4) && (blueCount == 0 && redCount == 5)) {
                System.out.println("恭喜你，中了四等奖，您的奖金为200元");

            }else if(blueCount == 1 && redCount == 5) {
                System.out.println("恭喜你，中了三等奖，您的奖金为3000元");

            }else if(blueCount == 0 && redCount == 6) {
                System.out.println("恭喜你，中了二等奖，您的奖金为"+(int)(maxMoney*0.3)+"万");

            }else if(blueCount == 1 && redCount == 6 ) {
                System.out.println("恭喜你，中了一等奖，您的奖金为"+maxMoney+"万");
            }


        }

        //判断数组中是否存在某数的方法，存在返回true
        public static boolean exist(int[] redBallRandom, int inputRandom) {
            for (int i = 0; i < redBallRandom.length; i++) {
                if(redBallRandom[i] == inputRandom) {
                    return true;
                }
            }
            return false;

        }


    }
}
